package org.example.core.autofill;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class AutoFillMataObjectHandler implements MetaObjectHandler {
    /**
     * 自动填充插入时的指定字段
     * @param metaObject 当前执行插入sql的源数据
     */
    @Override
    public void insertFill(MetaObject metaObject) {

       this.strictInsertFill(metaObject,"createdTime", LocalDateTime.class, LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
       this.strictUpdateFill(metaObject,"updatedTime", LocalDateTime.class, LocalDateTime.now());
    }
}
